//
//  UtilsMacros.h
//  zhima_kt
//
//  Created by zhima on 2020/3/4.
//  Copyright © 2020 zhima. All rights reserved.
//

#ifndef UtilsMacros_h
#define UtilsMacros_h

//拼接字符串
#define NSStringFormat(format,...) [NSString stringWithFormat:format,##__VA_ARGS__]


//颜色
#define KClearColor [UIColor clearColor]
#define KWhiteColor [UIColor whiteColor]
#define KBlackColor [UIColor blackColor]
#define KGrayColor [UIColor grayColor]
#define KGray2Color [UIColor lightGrayColor]
#define KBlueColor [UIColor blueColor]
#define KRedColor [UIColor redColor]
// RGB颜色转换（16进制->10进制）
#define UIColorFromRGB(rgbValue)\
\
[UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 \
alpha:1.0]

#define WEAK_VAR_VARNAME(var,name) __weak typeof(var) name = var
#define WEAKSELF(weakSelf) WEAK_VAR_VARNAME(self,weakSelf)

#define ios8 [[[UIDevice currentDevice] systemVersion ] floatValue] >= 8.0

#define ios7later [[[UIDevice currentDevice] systemVersion ] floatValue] >= 7.0

#define isNilOrNSNull(var) var && (NSNull *)var != [NSNull null]

#define DLOG(fmt, ...) NSLog((@"[DEBUG] %s [Line %d] --- " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
//-------------------获取设备大小-------------------------
//NavBar高度
#define NavigationBar_HEIGHT 44

//获取屏幕 宽度、高度
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
#define Screen_Bounds [UIScreen mainScreen].bounds

//iPhoneX / iPhoneXS /iPhone12 mini
#define  SIMEmojKeyBoardisIphoneX_XS        (SCREEN_WIDTH == 375.f && SCREEN_HEIGHT == 812.f ? YES : NO)

// iPhone12
#define  SIMEmojKeyBoardisIphone12        (SCREEN_WIDTH == 390.f && SCREEN_HEIGHT == 844.f ? YES : NO)


//iPhoneXR / iPhoneXSMax
#define  SIMEmojKeyBoardisIphoneXR_XSMax    (SCREEN_WIDTH == 414.f && SCREEN_HEIGHT == 896.f ? YES : NO)

//iPhone12 ProMax
#define  SIMEmojKeyBoardisIphone12ProMax    (SCREEN_WIDTH == 428.f && SCREEN_HEIGHT == 926.f ? YES : NO)

//异性全面屏
#define   SIMEmojKeyBoardisFullProfiledScreen    (SIMEmojKeyBoardisIphoneX_XS || SIMEmojKeyBoardisIphoneXR_XSMax || SIMEmojKeyBoardisIphone12 || SIMEmojKeyBoardisIphone12ProMax)

#define SIMEmojKeyBoardiPhoneX (SIMEmojKeyBoardisFullProfiledScreen)


//竖屏状态
//iPhoneX状态栏的高度 44
#define SIMEmojKeyBoardkState_Height (SIMEmojKeyBoardisFullProfiledScreen ? 44.0 : 20.0)
//NavigationBar的高度 44
#define SIMEmojKeyBoardkNavigationBar_Height 44.0
#define SIMEmojKeyBoardSafeAreaTopHeight (SIMEmojKeyBoardisFullProfiledScreen ? 88 : 64)
//底部非安全区域的高度 34
#define SIMEmojKeyBoardkBottomNOSafeArea_Height (SIMEmojKeyBoardisFullProfiledScreen ? 34.0 :0.0)
#define SIMEmojKeyBoardkTabBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height>20?83:49)

#define SIMEmojKeyBoardkStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height

#define SIMEmojKeyBoardkTopHeight (SIMEmojKeyBoardkStatusBarHeight + SIMEmojKeyBoardkNavigationBar_Height)

#define APPStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height

#define APPNaviBarHeight (APPStatusBarHeight + NavigationBar_HEIGHT)
//#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
//#define iPhone6 ([[UIScreen mainScreen] currentMode].size.height >= 1334 && [[UIScreen mainScreen] currentMode].size.height <= 2208? YES:NO)
//#define iPhone6p ([[UIScreen mainScreen] currentMode].size.height >= 2000 ? YES:NO)

//#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
//#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))

#define iPhone4 (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define iPhone5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
#define iPhone6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
#define iPhone6p (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)

#define iPadn ([[UIScreen mainScreen] currentMode].size.width == 1536 && [[UIScreen mainScreen] currentMode].size.height == 2048? YES:NO)
#define iPad2 ([[UIScreen mainScreen] currentMode].size.width == 768 && [[UIScreen mainScreen] currentMode].size.height == 1024? YES:NO)


//获取系统对象
#define kApplication        [UIApplication sharedApplication]
#define kAppWindow          [AppDelegate shareAppDelegate].window
#define kAppDelegate        [AppDelegate shareAppDelegate]
#define kRootViewController [UIApplication sharedApplication].delegate.window.rootViewController
#define kUserDefaults       [NSUserDefaults standardUserDefaults]
#define kNotificationCenter [NSNotificationCenter defaultCenter]
#define kWindow [UIApplication sharedApplication].keyWindow


#define kStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
#define kNavBarHeight (SIMEmojKeyBoardisFullProfiledScreen ? 88 : 64)
#define kTabBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height>20?83:49)
#define kTopHeight (kStatusBarHeight + kNavBarHeight)

//-------------------获取设备大小-------------------------

//G－C－D
#define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)

//NSUserDefaults 实例化
#define USER_DEFAULT [NSUserDefaults standardUserDefaults]


#define ValidStr(f) StrValid(f)
#define ValidDict(f) (f!=nil && [f isKindOfClass:[NSDictionary class]])
#define ValidArray(f) (f!=nil && [f isKindOfClass:[NSArray class]] && [f count]>0)
#define ValidNum(f) (f!=nil && [f isKindOfClass:[NSNumber class]])
#define ValidClass(f,cls) (f!=nil && [f isKindOfClass:[cls class]])
#define ValidData(f) (f!=nil && [f isKindOfClass:[NSData class]])

/// tabbar
#define TabVC @"vc"
#define TabTitel @"title"
#define TabImg @"icon"
#define TabSelectImg @"selectIcon"

//发送通知
#define KPostNotification(name,obj) [[NSNotificationCenter defaultCenter] postNotificationName:name object:obj];

//单例化一个类
#define SINGLETON_FOR_HEADER(className) \
\
+ (className *)shared##className;

#define SINGLETON_FOR_CLASS(className) \
\
+ (className *)shared##className { \
static className *shared##className = nil; \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
shared##className = [[self alloc] init]; \
}); \
return shared##className; \
}



#endif /* UtilsMacros_h */
